package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.mapper.BlackListMapper;
import com.tanhua.common.pojo.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Philcan
 * @version 1.0
 * @description: TODO
 * @date 2021/5/27 23:54
 */
@Service
public class BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;

    public IPage<BlackList> queryBlackList(Long userId, Integer page, Integer pageSize) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.orderByDesc("created");
        Page<BlackList> listPage = new Page<>(page, pageSize);
        return this.blackListMapper.selectPage(listPage, queryWrapper);
    }

    public Boolean delBlackList(Long id, Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id).eq("black_user_id", userId);
        return this.blackListMapper.delete(queryWrapper) > 0;
    }
}
